package com.easyidea.its.facade.department.impl;

import java.util.List;

import com.easyidea.its.domain.model.system.Department;
import com.easyidea.its.domain.service.department.DepartmentService;
import com.easyidea.its.facade.department.DepartmentMgr;

public class DepartmentMgrImpl implements DepartmentMgr {
  private DepartmentService departmentService;
	
  public int getDeparmentsCount(Department dept) {
		return departmentService.getDeparmentsCount(dept);
	}

	public List<Department> getDepartments(Department dept, int startAtIndex,
			int pageSize) {
		
		return departmentService.getDepartments(dept, startAtIndex, pageSize);
	}

	public boolean hasSameDeptName(String deptName, Integer id) {
		return departmentService.hasSameDeptName(deptName, id);
	}


	 public boolean saveOrUpdate(Department dept) {
	  if(this.hasSameDeptName(dept.getDepartmentName(), dept.getId())) {
		 return false; 
	  } else {
	 	  if(dept.getId() == -1) {
				 departmentService.save(dept);
			 } else {
				 Department old = this.getDepartmentById(dept.getId());
				 old.setDepartmentName(dept.getDepartmentName());
				 old.setDepartmentType(dept.getDepartmentType());
				 old.setDepartmentAddress(dept.getDepartmentAddress());
				 old.setTelephone(dept.getTelephone());
				 departmentService.update(old);
			 }
	 	  return true;
	  }

	 }
	
	 public Department getDepartmentById(Integer id) {
		 return departmentService.getBeanById(id);
	 }
	 public void removeDepartment(Integer id) {
		 departmentService.removeDepartment(id);
	 }
	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}
}
